package collection2;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class map2 {
    public static void main(String[] args) {

        HashMap<String,String> map1 = new HashMap<>();

        map1.put("b","a");
        map1.put("a","b");
        Set<Map.Entry<String, String>> entries = map1.entrySet();
        for (Map.Entry<String, String> entity:
             entries) {
            System.out.println(entity.getKey());//a,b自动排序
        }

        LinkedHashMap<String,String> map2 = new LinkedHashMap<>();

        map1.put("b","a");
        map1.put("a","b");
        Set<Map.Entry<String, String>> entries2 = map2.entrySet();
        for (Map.Entry<String, String> entity:
                entries2) {
            System.out.println(entity.getKey());//b,a保持存入顺序
        }


    }
}
